<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
	language="java"%>

<%@ taglib uri="/struts-tags" prefix="s"%>

<s:if test="operation == 'changepassword'">
	<h2>Thay đổi mật khẩu</h2>
</s:if>
<s:elseif test="isStaff()">
	<h2>Thông tin nhân viên</h2>
	<form action="registerStaff" method="get">
		<input type="submit" value="Thêm nhân viên" />
	</form>
</s:elseif>
<s:else>
	<h2>Thông tin tài khoản</h2>
</s:else>
<jsp:include page="formAccount.jsp"></jsp:include>

<s:if test="isStaff()">
	<hr>
	<div class="list-table">
		<h2>Danh sách nhân viên</h2>
		<table id="ver-zebra">
			<colgroup>
				<col class="vzebra-odd" />
				<col class="vzebra-even" />
				<col class="vzebra-odd" />
				<col class="vzebra-even" />
				<col class="vzebra-odd" />
				<col class="vzebra-even" />
				<col class="vzebra-odd" />
				<col class="vzebra-even" />
				<col class="vzebra-odd" />
			</colgroup>
			<thead>
				<tr>
					<th scope="col" id="vzebra-comedy">Chọn</th>
					<th scope="col" id="vzebra-adventure">Tên nhân viên</th>
					<th scope="col" id="vzebra-adventure">Email</th>
					<th scope="col" id="vzebra-adventure">Điện thoại</th>
					<th scope="col" id="vzebra-adventure">Quản lý sân</th>
					<th scope="col" id="vzebra-adventure">Trạng thái</th>
				</tr>
			</thead>
			<tbody>
				<s:if test="%{staffLst.isEmpty()}">
					<tr>
						<td colspan="8">Chưa có dữ liệu</td>
					</tr>
				</s:if>
				<s:else>
					<s:iterator value="staffLst">
						<tr>
							<td><s:if test="status">
									<input type="radio" name="select" id="select"
										onchange="resetValidate();"
										onfocus="setAccountInfo('<s:property value="id"/>','<s:property value="username" />','<s:property value="password" />',
								'<s:property value="person.name" />','<s:property value="person.email" />','<s:property value="person.address" />','<s:property value="person.phone" />',
								'<s:property value="getSoccerFieldId(person.id)" />','<s:property value="getSoccerFieldName(person.id)" />')" />
								</s:if> <s:else>x
							</s:else></td>
							<td><s:property value="person.name" /></td>
							<td><s:property value="person.email" /></td>
							<td><s:property value="person.phone" /></td>
							<td><s:property value="getSoccerFieldName(person.id)" /></td>
							<td><s:if test="status">
										Kích hoạt
								</s:if> <s:else>
										Đã bị xóa
								</s:else></td>
						</tr>
					</s:iterator>
				</s:else>
			</tbody>
		</table>
	</div>

	<script type="text/javascript">
		var oldId;
		function setAccountInfo(id, username, password, name, email, address,
				phone, soccerFieldId, soccerFieldName) {
			$('#id').val(id);
			$('#username').val(username);
			$('#password').val(password);
			$('#name').val(name);
			$('#email').val(email);
			$('#phone').val(phone);
			$('#address').val(address);

			if (oldId) {
				$("#soccerFieldId option[value='" + oldId + "']").remove();
			}

			oldId = soccerFieldId;
			$('#soccerFieldId').append(
					'<option value="'+soccerFieldId+'">' + soccerFieldName
							+ '</option>');
			$('#soccerFieldId').val(soccerFieldId);

			return false;
		}

		function resetValidate() {
			$('#error_message').css('display', 'none');
			$('label.error').hide();
			$('.error').removeClass('error');
		}
	</script>
</s:if>
